package com.comall.dc.banktest.query;

import com.comall.dc.banktest.domain.exception.AccountNotExistException;
import com.comall.dc.banktest.domain.model.Account;
import com.comall.dc.banktest.infrastructure.dao.service.AccountDAO;
import com.comall.dc.banktest.infrastructure.entity.AccountPO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;

@Service
public class AccountQuery {

    @Autowired
    private AccountDAO accountDAO;



    /**
     * 根据ID查询账号基本信息
     * @param id 账户ID
     * @return 账户信息
     * @throws AccountNotExistException 账户不存在异常
     */
    public Account getById(Integer id) throws AccountNotExistException {
        return new Account(Optional.ofNullable(accountDAO.getById(id))
                .orElseThrow(AccountNotExistException::new));
    }

    /**
     * 根据开户时间区间、模糊ID、模糊身份证号、模糊用户电话查询账户列表
     * @param beginTime 开始时间
     * @param endTime 结束时间
     * @param likeId 模糊ID
     * @param likeIdCard 模糊身份证号
     * @param likeUserPhone 模糊用户电话
     * @return 账户信息列表
     */
    public List<AccountPO> listAccountByTimeRangeAndLikeIdAndLikeIdCardAndLikeUserPhone(
            LocalDateTime beginTime, LocalDateTime endTime, String likeId, String likeIdCard, String likeUserPhone){
        return accountDAO.listByTimeRangeAndLikeIdAndLikeIdCardAndLikeUserPhone(
                beginTime, endTime, likeId, likeIdCard, likeUserPhone);
    }

}
